package com.test.main;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JRExporterParameter;
import net.sf.jasperreports.engine.JasperExportManager;
import net.sf.jasperreports.engine.JasperFillManager;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
import net.sf.jasperreports.engine.export.JRPdfExporter;
import net.sf.jasperreports.engine.util.AbstractSampleApp;
import net.sf.jasperreports.export.SimpleExporterInput;
import net.sf.jasperreports.export.SimpleOutputStreamExporterOutput;

public class GeneratePdf4Group extends AbstractSampleApp
{

	public static void main(String[] args)
	{
		//main(new GeneratePdf(), args);
		try
		{
			new GeneratePdf4Group().test();
		} catch (JRException e)
		{
			
			e.printStackTrace();
		}

	}

	@Override
	public void test() throws JRException
	{
		fill();
		//pdf();
		
	}

	public void fill() throws JRException
	{
		long start = System.currentTimeMillis();
		
		List attList = new ArrayList<AttorneyABGroup>();
		
		List perList = new ArrayList<Person>();
		
		List groupA = new ArrayList<Person>();
		List groupB = new ArrayList<Person>();
		
		Map<String,Object> parameters = new HashMap<String,Object>();
		parameters.put("projectName", "海南金海浆纸业有限公司2C洗浆机所用之马达项目");
		parameters.put("engProjectName", "JHPP MOTORS FOR 2C WASH PRESS Project");
		parameters.put("validFromEn", "July 07,2016");
		parameters.put("validToEn", "Octomber 06,2016");
		
		parameters.put("validFromCn", "2016年07月07日");
		parameters.put("validToCn", "2016年10月06日");
		
		parameters.put("code", "SC0116POA000001");
		parameters.put("uuid", "1234567890123456ABCDEFGHIJKLMNOP");
		
		parameters.put("engNegoType", "including signing contract(s)");
		parameters.put("chnNegoType", "含合同签署");

		//Person p1 = new Person("Mr. Guo Xiang Yang","Ms. Wu Wen Yan","郭向阳 先生","吴文琰 女士");
		
		Person p1 = new Person("Mr. Guo Xiang Yang","郭向阳 先生");
		
		p1.setEngPosition("Sales Director Region South");
		p1.setChnPosition("华南区销售总监");
		p1.setEngDept("FFI");
		p1.setChnDept("森林与纤维行业部");
		p1.setEngDivision("Large Drivers");
		p1.setChnDivision("大型传动部");
		p1.setEngBU("Process Industries and Drivers");
		p1.setChnBU("过程工业与驱动集团");
		groupA.add(p1);
		
		Person p2 = new Person("Mr. Guo Jun Qin","郭俊钦 先生");
		p2.setEngPosition("Project Manager");
		p2.setChnPosition("项目经理");
		p2.setEngDept("OEC");
		p2.setChnDept("工程运营中心部");
		p2.setEngDivision("Large Drivers");
		p2.setChnDivision("大型传动部");
		p2.setEngBU("Process Industries and Drivers");
		p2.setChnBU("过程工业与驱动集团");
		
		groupA.add(p2);
		
		
		
		Person p3 = new Person("Ms. Wu Wen Yan", "吴文琰 女士");
		p3.setEngPosition("Senior Commercial Officer");
		p3.setChnPosition("高级商务专员");
		p3.setEngDept("LD Projects BA");
		p3.setChnDept("大型传动项目商务部");
		p3.setEngDivision("Large Drivers");
		p3.setChnDivision("大型传动部");
		p3.setEngBU("Process Industries and Drivers");
		p3.setChnBU("过程工业与驱动集团");
		groupB.add(p3);
		
		Person p4 = new Person("Ms. Yuan Jie Ying","袁洁莹 女士");
		p4.setEngPosition("Commercial Officer");
		p4.setChnPosition("商务专员");
		p4.setEngDept("LD Projects BA");
		p4.setChnDept("大型传动项目商务部");
		p4.setEngDivision("Large Drivers");
		p4.setChnDivision("大型传动部");
		p4.setEngBU("Process Industries and Drivers");
		p4.setChnBU("过程工业与驱动集团");
		groupB.add(p4);
		
		parameters.put("groupA", groupA);
		parameters.put("groupB", groupB);
		
		AttorneyABGroup abGroup = new AttorneyABGroup();
		
		JRBeanCollectionDataSource datas = new JRBeanCollectionDataSource(perList);
		
		abGroup.setTable_datas(datas);
		
		attList.add(abGroup);
		
		JasperPrint jp  = JasperFillManager.fillReport("D:\\viedo\\软件素材\\jasper\\report\\SLC_GROUP.jasper", parameters, new JRBeanCollectionDataSource(attList));
		
		JasperExportManager.exportReportToPdfFile(jp,"D:\\viedo\\软件素材\\jasper\\report\\SLC_GROUP_including signing contract(s).pdf");

		jp  = JasperFillManager.fillReport("D:\\viedo\\软件素材\\jasper\\report\\SITL_GROUP.jasper", parameters, new JRBeanCollectionDataSource(attList));
		
		JasperExportManager.exportReportToPdfFile(jp,"D:\\viedo\\软件素材\\jasper\\report\\SITL_GROUP_including signing contract(s).pdf");

		
		parameters.put("engNegoType", "excluding signing contract(s)");
		parameters.put("chnNegoType", "合同签署除外");
		jp  = JasperFillManager.fillReport("D:\\viedo\\软件素材\\jasper\\report\\SLC_GROUP.jasper", parameters, new JRBeanCollectionDataSource(attList));
		
		JasperExportManager.exportReportToPdfFile(jp,"D:\\viedo\\软件素材\\jasper\\report\\SLC_GROUP_excluding signing contract(s).pdf");

		jp  = JasperFillManager.fillReport("D:\\viedo\\软件素材\\jasper\\report\\SITL_GROUP.jasper", parameters, new JRBeanCollectionDataSource(attList));
		
		JasperExportManager.exportReportToPdfFile(jp,"D:\\viedo\\软件素材\\jasper\\report\\SITL_GROUP_excluding signing contract(s).pdf");
		
		System.err.println("PDF creation time : " + (System.currentTimeMillis() - start));
		
		//System.err.println("Filling time : " + (System.currentTimeMillis() - start));
	}
	
	
	/**
	 *
	 */
	public void pdf() throws JRException
	{
		long start = System.currentTimeMillis();
		//JasperExportManager.exportReportToPdfFile("D:\\viedo\\svn_project\\workshop\\JasperDemo\\src\\test.jrprint");
		JRPdfExporter exporter = new JRPdfExporter();
		
		exporter.setExporterInput(new SimpleExporterInput("D:\\viedo\\svn_project\\workshop\\JasperDemo\\src\\SLC_GROUP.jrprint"));
		exporter.setExporterOutput(new SimpleOutputStreamExporterOutput("D:\\viedo\\svn_project\\workshop\\JasperDemo\\src\\SLC_GROUP.pdf"));
		
		exporter.exportReport();
		
		System.err.println("PDF creation time : " + (System.currentTimeMillis() - start));
	}
	
}
